/**
 * 
 */
package cc.rico.jms.spring.producer.impl;

import javax.jms.Destination;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import cc.rico.jms.spring.bean.CustomUser;
import cc.rico.jms.spring.producer.ProducerService;

/**
 * @author rico 2016年7月31日
 *
 */
@Service(value="producerService")
public class ProducerServiceImpl implements ProducerService {
	private static final Logger logger = LoggerFactory.getLogger(ProducerServiceImpl.class);
	
	@Autowired
	@Qualifier(value="jmsTemplate")
	private JmsTemplate jmsTemplate;

	/* (non-Javadoc)
	 * @see cc.rico.jms.service.ProducerService#sendMessage(javax.jms.Destination, java.lang.String)
	 */
	@Override
	public void sendMessage(Destination destination, final String message) {
		logger.info("##ProducerService.sendMessage##message={}", message);
		
//		jmsTemplate.send(destination, new MessageCreator() {
//			@Override
//			public Message createMessage(Session session) throws JMSException {
//				return session.createTextMessage(message);
//			}
//		});
		
		CustomUser user = new CustomUser();
		user.setPassword("121");
		user.setUsername("rico");
		jmsTemplate.convertAndSend(destination, user);
	}
}
